// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst 

package net.minecraft.util;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.*;

public class Zipper
{

    static final int BUFFER = 2048;

    public Zipper()
    {
    }

    public static boolean zipFolders(File afile[], File file)
    {
        return zipFolders(afile, file, "");
    }

    public static boolean zipFolders(File afile[], File file, String s)
    {
        try
        {
            //Object obj = null;
            FileOutputStream fileoutputstream = new FileOutputStream(file);
            ZipOutputStream zipoutputstream = new ZipOutputStream(new BufferedOutputStream(fileoutputstream));
            File afile1[] = afile;
            int i = afile1.length;
            for(int j = 0; j < i; j++)
            {
                File file1 = afile1[j];
                if(!addToZip(file1.getParentFile().getPath(), s, file1.getName(), zipoutputstream))
                {
                    return false;
                }
            }

            zipoutputstream.close();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
        return true;
    }

    protected static boolean addToZip(String s, String s1, String s2, ZipOutputStream zipoutputstream)
    {
        File file = new File((new StringBuilder()).append(s).append(File.separator).append(s2).toString());
        System.out.println((new StringBuilder()).append("Adding \"").append(s).append(File.separator).append(s2).append("\" file").toString());
        if(file.isHidden())
        {
            return true;
        }
        if(file.isDirectory())
        {
            s = (new StringBuilder()).append(s).append(File.separator).append(file.getName()).toString();
            s1 = (new StringBuilder()).append(s1).append(File.separator).append(file.getName()).toString();
            String as[] = file.list();
            int i = as.length;
            for(int j = 0; j < i; j++)
            {
                String s3 = as[j];
                if(!addToZip(s, s1, s3, zipoutputstream))
                {
                    return false;
                }
            }

            return true;
        }
        try
        {
            byte abyte0[] = new byte[2048];
            FileInputStream fileinputstream = new FileInputStream(file);
            BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream, 2048);
            ZipEntry zipentry = new ZipEntry((new StringBuilder()).append(s1).append(File.separator).append(s2).toString());
            zipoutputstream.putNextEntry(zipentry);
            int k;
            while((k = bufferedinputstream.read(abyte0, 0, 2048)) != -1) 
            {
                zipoutputstream.write(abyte0, 0, k);
            }
            bufferedinputstream.close();
        }
        catch(Exception exception)
        {
            Logger.getLogger((net.minecraft.util.Zipper.class).getName()).log(Level.SEVERE, null, exception);
            return false;
        }
        return true;
    }

    public static boolean zipFolder(File file, File file1)
    {
        File afile[] = new File[1];
        afile[0] = file;
        return zipFolders(afile, file1);
    }

    public static void unzipFolder(File file, File file1)
    {
        try
        {
            //Object obj = null;
            FileInputStream fileinputstream = new FileInputStream(file);
            ZipInputStream zipinputstream = new ZipInputStream(new BufferedInputStream(fileinputstream));
            ZipEntry zipentry;
            while((zipentry = zipinputstream.getNextEntry()) != null) 
            {
                System.out.println((new StringBuilder()).append("Extracting: ").append(zipentry).toString());
                byte abyte0[] = new byte[2048];
                File file2 = new File((new StringBuilder()).append(file1).append(File.separator).append(zipentry.getName()).toString());
                if(file2.getParentFile() != null && !file2.getParentFile().exists())
                {
                    file2.getParentFile().mkdirs();
                }
                if(!file2.exists())
                {
                    file2.createNewFile();
                    file2.getParent();
                }
                FileOutputStream fileoutputstream = new FileOutputStream(file2);
                BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream, 2048);
                int i;
                while((i = zipinputstream.read(abyte0, 0, 2048)) != -1) 
                {
                    bufferedoutputstream.write(abyte0, 0, i);
                }
                bufferedoutputstream.flush();
                bufferedoutputstream.close();
            }
            zipinputstream.close();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }
}
